let str = "hello"
let arr = [1, 2, 3, 5, 8, 6, 0, 9]
function handleNext(arr) {
  let index = 0
  return {
    next: () => {
      if (index < arr.length) {
        return {
          value: arr[index++],
          done: false
        }
      }
      return {
        value: undefined,
        done: true
      }
    }
  }
}

let iterator = handleNext(str)
console.log(iterator.next());
console.log(iterator.next());
console.log(iterator.next());
console.log(iterator.next());
console.log(iterator.next());
console.log(iterator.next());